package testJboss2Web;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.naming.InitialContext;
import javax.servlet.http.HttpServlet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import testJboss2.Email;
import testJboss2.User;
import testJboss2.UserManager;
import testJboss2.UserManagerBean;

public class TestJboss2Web extends HttpServlet {
	private static final long serialVersionUID = 1L;

	//UserManager um = new UserManagerBean();

	//	@EJB
	UserManager um;

	private UserManager getUserManager() {
		try {
			InitialContext ctx = new InitialContext();
			return (UserManager) ctx.lookup("testJboss2/UserManagerBean/local");
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("couldn't lookup Dao", e);
		}
	}

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.um = this.getUserManager();
		
		this.test1(resp);
	}
	
	private void test1(HttpServletResponse resp) throws IOException{
		resp.getWriter().println("test1");
		
		User u;
		//u = this.um.addUser("Liviu", "Grigorescu", new Email("grigoresculiviu@gmail.com"), null);
		this.um.deleteUser(1);
		System.out.println("liviu");
	}
}
